const base = require('../base/baseObj')
const con = require('../../config/const')
const isObject = require('lodash/isObject')

// 获取post参数
const postParam = (req, res, next) => {
    let query = req.body.query || '', successStr = ''

    if(query === ''){
        res.json( base.param_err(query, '没有找到query参数') )
    }
    try{
        if(!isObject(query)) {query = JSON.parse(query) }
    }catch(e){
        res.json( base.param_err(query, 'query参数不能转为json对象:' + e.message) )
    }
    successStr = req.body.success || (con.SUCCESS_STATUS + '')
    let successArr = isObject(successStr) ? successStr : successStr.split(',')
    return {query: query, successArr: successArr}
}



module.exports = postParam